package maze.logic;

import maze.model.Cell;
import maze.model.Map;
import maze.model.type.Face;

public class AutoLogic extends Logic
{
	/**
	 * current moving direction
	 */
	private Face face = Face.NORTH;

	@Override
	public void init()
	{
	}

	@Override
	public void logic()
	{
		super.logic();

		if (!LogicManager.getInstance().moving)
		{
			Cell cell = Map.getInstance().cells[sun.pos.x][sun.pos.y];

			if (cell.canWallPass(face.next()))
			{
				// try turn right
				face = face.next();
			}
			else if (cell.canWallPass(face))
			{
				// try move forward
			}
			else if (cell.canWallPass(face.next().next().next()))
			{
				// try turn left
				face = face.next().next().next();
			}
			else
			{
				// try move backward
				face = face.next().next();
			}

			move(face);
		}
	}
}
